home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Web Graphics with Shout 3D
/
Interactive Web Graphics With Shout 3D.iso
/
mac
/
Code
/
Chapter Code.exe
/
Chapter11
/
ScanTheSkiesDisplay.java
< prev
next >
Wrap
Text File
|
2000-07-25
|
2KB
|
65 lines
package custom_nodes;
import shout3d.core.*;
import shout3d.*;
import java.awt.*;
public class ScanTheSkiesDisplay extends PostRenderEffect{
final public IntField score = new IntField(this, "score", Field.NON_NEGATIVE_INT, 0);
final public IntField shotClock = new IntField(this, "shotClock", Field.NON_NEGATIVE_INT, 0);
//constructor
public ScanTheSkiesDisplay(){
}
public void filter(Graphics g, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight){
//initialize display strings
String scoreString = ""+score.getValue();
String clockString = ""+shotClock.getValue();
String message = "CLICK TO START";
//if shot clock is at zero
//display CLICK TO START
if (shotClock.getValue() == 0) {
Font f = new Font("SansSerif", Font.BOLD, 30);
FontMetrics fm = g.getFontMetrics(f);
int stringWidth = fm.stringWidth(message);
g.setFont(f);
g.setColor(java.awt.Color.yellow);
g.drawString(message, (deviceWidth - stringWidth)/2, deviceHeight/2);
}
//if game is running
//draw sight rectangle
else {
//red in final 3 seconds
//as warning
if (shotClock.getValue() < 4) {
g.setColor(java.awt.Color.red);
}
//otherwise yellow
else {
g.setColor(java.awt.Color.yellow);
}
g.drawRect((deviceWidth/2)-25, (deviceHeight/2)-25, 50, 50);
}
//set up score and shot clock display
g.setFont( new Font("SansSerif", Font.BOLD, 16));
g.setColor(java.awt.Color.yellow);
g.drawString(scoreString, deviceWidth - 50, 30);
g.drawString(clockString, 50, 30);
}
}